<script setup>
import Toast from '@vant/weapp/dist/toast/toast';
import { toPage } from '../public.js'

import { watch, ref } from 'vue';

const props = defineProps({
    list: {
        type: Array,
        default: []
    }
})

const featureObj = ref({
    oneList: [],
    twoList: []
})

watch(() => props.list, (val) => {
    if (val.length) {
        featureObj.value.oneList = val.slice(0, 8);
        featureObj.value.twoList = val.slice(8);
    }

}, { deep: true, immediate: true })

</script>

<template>
    <div class='swiperItem'>
        <swiper indicator-dots indicator-color="#424257" indicator-active-color="#FFF" class="two_box_swiper">
            <swiper-item class="two_box_swiper_item">
                <div class="two_item" v-for="item of featureObj.oneList" @click="toPage(item)">
                    <div class="two_item_imgBox">
                        <img :src="item?.imageUrl" mode="aspectFill" class="two_item_img" alt="">
                    </div>
                    <div>{{ item?.title }}</div>
                </div>
            </swiper-item>
            <swiper-item class="two_box_swiper_item">
                <div class="two_item" v-for="item of featureObj.twoList" @click="toPage(item)">
                    <div class="two_item_imgBox">
                        <img :src="item?.imageUrl" mode="aspectFill" class="two_item_img" alt="">
                    </div>
                    <div>{{ item?.title }}</div>
                </div>
            </swiper-item>
        </swiper>
    </div>
</template>

<style lang='scss' scoped>
.swiperItem {
    height: 400rpx;

    .two_box_swiper {
        height: 100%;

        .two_box_swiper_item {
            box-sizing: border-box;
            display: flex;
            flex-wrap: wrap;
            padding: 0 0 40rpx;

            .two_item {
                width: 24%;
                flex-shrink: 0;
                display: flex;
                flex-direction: column;
                align-items: center;
                height: 150rpx;
                // justify-content: center;
                gap: 12rpx;
                font-size: 24rpx;
                color: #E6F1FA;
                margin: 0 80rpx 0 0;
                text-align: center;

                &:not(:nth-child(4n)) {
                    margin-right: calc(4% / 3);
                }

                &:nth-child(4n) {
                    margin-right: 0;
                }

                &:nth-child(-n+4) {
                    margin-top: 0;
                }


                .two_item_imgBox {
                    flex-shrink: 0;
                    width: 100rpx;
                    height: 100rpx;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    background: #221F49;
                    border-radius: 24rpx;

                    .two_item_img {
                        width: 54rpx;
                        height: 54rpx;
                    }
                }
            }
        }
    }
}
</style>